<?php

namespace App\Http\Controllers\Home\Chat;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Cookie;

class UserController extends Controller {
    //
    /**
     * 存储聊天进入的用户
     */
    public function user(Request $request) {
        $data = $request->input('data');
        if(!empty($data)) {
            $ret = Cache::get('Chat');
            if(empty($ret) && !is_array($ret)) {
                return $this->ajax(true, '准备连接服务');
            }
            $userName = array_values($ret);
            if(in_array($data, $userName)) {
                return $this->ajax(false, '用户名已经存在');
            } else {
                return $this->ajax(true, '准备连接服务');
            }
        } else {
            return $this->ajax(false, '进入失败');
        }
    }

    public function gets(Request $request) {
        $ret = Cache::get('Chat');
        return $this->ajax(true, $ret);
    }
}
